package ar.uade.distribuidas.tpo.web.servlets;

import java.io.IOException;
import java.net.InetAddress;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ar.uade.distribuidas.tpo.base.dominiodto.ClienteDTO;
import ar.uade.distribuidas.tpo.web.delegado.BD;


/**
 * Servlet implementation class BajaCliente
 */
@WebServlet("/BajaCliente")
public class BajaCliente extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BajaCliente() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
	    
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/bajacliente.jsp");
		   
		  
			
			Long cuil = Long.valueOf(request.getParameter("cuil"));
			ClienteDTO cDTO = new ClienteDTO (cuil, "");
			
			try{
				
				BD.getInstance().bajaCliente(cDTO);
				
			request.setAttribute("allok", "La solicitud fue procesada correctamente.");
			
			 request.getRequestDispatcher("/jsp/bajacliente.jsp").forward(request, response);
			
			} catch (Exception e) {
				
				request.setAttribute("allerror", "Hubo un error al procesar la solicitud.");
				request.getRequestDispatcher("/jsp/bajacliente.jsp").forward(request, response);
				
				
				
			} 
	}

}
